package org.mspring.mlog.duoshuo.sync;

import com.alibaba.fastjson.JSONObject;

/**
 * @author GaoYoubo
 * @since 2015/2/18
 */
public class SyncResponse {
    private long logId; //记录id。按时间顺序递增。
    private long userId; //对评论执行该操作的用户id。
    private SyncAction action; //操作类型： create 创建评论, approve 通过评论, spam 标记垃圾评论, delete 删除评论, delete-forever 彻底删除评论
    private long date; //执行该操作的时间戳。
    private String meta; //根据操作类型不同，meta的类型会有变化。 当action为approve,spam,delete,delete-forever之一时，meta为array。数组每一个项为一条评论的id。


    public static SyncResponse fromJsonObject(JSONObject object) {
        SyncResponse rsp = new SyncResponse();
        rsp.setLogId(object.getLongValue("log_id"));
        rsp.setUserId(object.getLongValue("user_id"));
        rsp.setAction(SyncAction.newInstance(object.getString("action")));
        rsp.setDate(object.getLongValue("date"));
        rsp.setMeta(object.getString("meta"));
        return rsp;
    }

    public long getLogId() {
        return logId;
    }

    public void setLogId(long logId) {
        this.logId = logId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public SyncAction getAction() {
        return action;
    }

    public void setAction(SyncAction action) {
        this.action = action;
    }

    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public String getMeta() {
        return meta;
    }

    public void setMeta(String meta) {
        this.meta = meta;
    }
}
